﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace TooltracePC
{
    class dbAdmin : clsDatabase
    {
        private static int nAdminCount = 0;


        public int getAdminCount()
        {
            if(nAdminCount > 0)
            {
                return nAdminCount;
            }
            setAdminCount();
            return nAdminCount;
        }

        /*set*/
        private void setAdminCount()
        {
            string strSql = @"select count(*) AS c from Admin";
            DataTable dtTool = null;
            dtTool = SelectToDataTable(strSql);
            nAdminCount = (int)dtTool.Rows[0]["c"];
        }

        /*get*/
        public DataTable getAdminByName(string uname)
        {
            DataTable dt = null;
            if (string.IsNullOrEmpty(uname))
            {
                return dt; 
            }

            string strSql = @"select AdminName AS u, AdminPass AS p from Admin WHERE AdminName = '" + uname + "'";
            dt = SelectToDataTable(strSql);
            return dt;
        }

        //update
        public void updatePass(string pass, string uname)
        {
            if (string.IsNullOrEmpty(pass) || string.IsNullOrEmpty(uname))
            {
                return ;
            }

            string strSql = "update Admin set AdminPass = '"+ pass + "' where AdminName = '"+ uname + "'";
            execNonSQL(strSql);
        }
    }
}
